﻿Imports System.Net.Mail
Imports System.Deployment.Application
Imports System.Data
Imports System.Data.SqlClient
Imports System.Net
Imports System.IO
Imports Microsoft.Win32
Imports System.Runtime.InteropServices
Imports System.Security.Principal
Imports System.Text

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles sendmsg_btn.Click

        Dim Smtp_Server As New SmtpClient
        Dim e_mail As New MailMessage()
        Smtp_Server.UseDefaultCredentials = False
        Smtp_Server.Credentials = New Net.NetworkCredential("miegrouphelpdesk@miegroup.nl", "MIE!^(#EE")
        Smtp_Server.Port = 2525
        Smtp_Server.EnableSsl = True
        Smtp_Server.Host = "mail.miegroup.nl"

        If school_txt.Text = "" Then
            MsgBox("U moet een schoolnaam invullen.")
        ElseIf locatie_txt.Text = "" Then
            MsgBox("U moet een locatie Kiezen." & Environment.NewLine & "Zijn er geen andere locaties? " & Environment.NewLine & "Kies dan voor N.V.T. .")
        ElseIf name_txt.Text = "" Then
            MsgBox("U moet uw naam invullen.")
        ElseIf from_txt.Text = "" Then
            MsgBox("U moet een geldig e-mailadres invullen.")
        ElseIf subject_txt.Text = "" Then
            MsgBox("U moet een onderwerp invullen.")
        ElseIf groep_txt.Text = "" Then
            MsgBox("U moet een groep invullen.")
        ElseIf text_txt.Text = "" Then
            MsgBox("U moet een bericht / Omschrijving invullen.")


        Else
            e_mail = New MailMessage()
            e_mail.To.Add(New MailAddress("helpdesk@miegroup.nl"))
            e_mail.CC.Add(New MailAddress(from_txt.Text))
            e_mail.From = New MailAddress(from_txt.Text, name_txt.Text, System.Text.Encoding.UTF8)
            e_mail.Subject = school_txt.Text + " " + "Groep: " + groep_txt.Text + " " + subject_txt.Text
            e_mail.IsBodyHtml = True
            e_mail.Body = _
                    "<html>" & _
                    "<head>" & _
                    "<title></title>" & _
                        "<meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"">" & _
                    "</head>" & _
                    "<body bgcolor=""#FFFFFF"" rightmargin=""150"" leftmargin=""0"" topmargin=""0"" marginwidth=""0"" marginheight=""0"">" & _
                        "<table width=""914"" height=""353"" border=""1"" cellpadding=""0"" cellspacing=""0"" id=""Tabel_01"">" & _
                            "<tr>" & _
                                "<td colspan=""4""><img src=""http://www.miegroep.nl/supporttool/images/Naamloos-2_01.gif"" width=""914"" height=""98"" alt=""></td>" & _
                            "</tr>" & _
                            "<tr>" & _
                                "<td colspan=""3"">" & _
                                    "<table width=""467"" border=""0"">" & _
                            "<tr>" & _
                                "<td width=""146"">School:</td>" & _
                                "<td width=""281"">" + school_txt.Text + "</td>" & _
                            "</tr>" & _
                            "<tr>" & _
                                "<td width=""146"">Computernaam:</td>" & _
                                "<td width=""281"">" + pc_txt.Text + "</td>" & _
                            "</tr>" & _
                            "<tr>" & _
                                "<td>Naam:</td>" & _
                                "<td>" + name_txt.Text + "</td>" & _
                            "</tr>" & _
                            "<tr>" & _
                                "<td>Locatie of Straatnaam:</td>" & _
                                    "<td>" + locatie_txt.Text + "</td>" & _
                            "</tr>" & _
                            "<tr>" & _
                                "<td>Groep:</td>" & _
                                    "<td>" + groep_txt.Text + "</td>" & _
                            "</tr>" & _
                            " <tr> " & _
                                "<td>Bericht:</td>" & _
                                    "<td>" + text_txt.Text + "</td>" & _
                            "</tr>" & _
                            "<tr> " & _
                                "<td>Telefoon Nummer:</td>" & _
                                    "<td>" + telefoon_txt.Text + "</td>" & _
                            "</tr>" & _
                            "<tr>" & _
                                "<td>Priv&eacute; of Werk:</td>" & _
                                    "<td>" + priveofwerk.Text + "</td>" & _
                            "</tr>" & _
                            "<tr>" & _
                                " <td>Teamviewer ID:</td> " & _
                            "<td>" + teamviewerid_txt.Text + "</td>" & _
                            "</tr>" & _
                        "</table>" & _
                        " </td>" & _
                        "</tr>" & _
                    "</table>" & _
                    "</body>" & _
                    "</html>"

            If screenshot1.Text = "" Then

            ElseIf screenshot1.Text IsNot "" Then
                Dim oAttch As Mail.Attachment = New Mail.Attachment(screenshot1.Text)
                e_mail.Attachments.Add(oAttch)
            End If
            Smtp_Server.Send(e_mail)
            NotifyIcon1.Icon = SystemIcons.Information
            NotifyIcon1.BalloonTipTitle = "Uw bericht is verzonden"
            NotifyIcon1.BalloonTipText = "We zullen z.s.m. contact met u opnemen."
            NotifyIcon1.BalloonTipIcon = ToolTipIcon.Info
            NotifyIcon1.Visible = True
            NotifyIcon1.ShowBalloonTip(30000)

            mailsent.Text = "Uw bericht is verzonden."
            ' Mail is verstuurd, nu alle velden behalve schoolnaam en emailadres leegmaken.
            subject_txt.Text = ""
            name_txt.Text = ""
            groep_txt.Text = ""
            text_txt.Text = ""
            screenshot1.Text = ""
        End If
    End Sub
    Private Sub AboutToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AboutToolStripMenuItem.Click
        AboutBox1.Show()
    End Sub
    Private Sub AfsluitenToolStripMenuItem_Click_1(sender As Object, e As EventArgs) Handles AfsluitenToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs)
        screenshot.Show()
    End Sub

    Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        My.Settings.school = school_txt.Text
        My.Settings.emailadres = from_txt.Text
    End Sub

    Private Sub browse_btn_Click(sender As Object, e As EventArgs) Handles browse_btn.Click
        Dim openFileDialog As New OpenFileDialog()
        openFileDialog.InitialDirectory = "H:\"
        Using O As New OpenFileDialog With {.Filter = "(Image Files)|*.jpg;*.png;*.bmp;*.gif;*.ico|Jpg, | *.jpg|Png, | *.png|Bmp, | *.bmp|Gif, | *.gif", .Multiselect = False, .Title = "Selecteer de Schermafdruk"}
            If O.ShowDialog = 1 Then
                screenshot1.Text = O.FileName
            End If
        End Using
    End Sub
    Private Sub ScreenshotMakenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ScreenshotMakenToolStripMenuItem.Click
        screenshot.Show()
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Teamviewer id ophalen uit register.
        If Environment.Is64BitOperatingSystem = True Then
            'Teamviewer Registry Path 64 Bit Windows
            Dim readvalue As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\Wow6432Node\Teamviewer\Version8", "ClientID", Nothing)
            teamviewerid_txt.Text = readvalue
        ElseIf Environment.Is64BitOperatingSystem = False Then
            'Teamviewer Registry Path 32 Bit Windows
            Dim readvalue As String = My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\Software\Teamviewer\Version8", "ClientID", Nothing)
            teamviewerid_txt.Text = readvalue
        End If
        ' Velden vooraf invullen met ingevulde waardes laatste gebruik. 
        pc_txt.Text = System.Net.Dns.GetHostName
        school_txt.Text = My.Settings.school
        from_txt.Text = My.Settings.emailadres
    End Sub
End Class

